<?php

namespace App\Admin\Controllers;

use App\ChangfangdiConfig;
use App\Project;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ChangfangdiController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '厂房帝小程序来源配置';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ChangfangdiConfig());

        $grid->column('id', __('Id'));
        $grid->column('create_user_id', __('创建者'))->display(function($value){
            return User::find($value)->realname;
        });
        $grid->column('project_id', __('项目'))->display(function($value){
            return Project::find($value)->name;
        });


        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ChangfangdiConfig::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('create_user_id', __('Create user id'));
        $show->field('project_id', __('Project id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ChangfangdiConfig());

        $form->select('create_user_id', __('创建者'))->options(User::getSelectOptions())->required();;
        $form->select('project_id', __('项目'))->options(Project::getSelectOptions())->required();;

        return $form;
    }
}
